/**
 * TransferId.java
 */
package fss.transfer;

import java.io.Serializable;

import fss.util.rmi.RmiId;

/**
 * The identifier for a transfer (download or upload).
 * 
 * @author thinh
 *
 */
public class TransferId implements Serializable {
    private static final long serialVersionUID = 1L;
    /**
     * The transfer activity type.
     */
    private TransferType type = null;
    /**
     * The source type (client or service).
     */
    private TransferSource sourceType = null;
    /**
     * The source id.
     */
    private RmiId sourceId = null;
    /**
     * The destination id.
     */
    private RmiId destinationId = null;
    /**
     * The filename.
     */
    private String filename = null;
    /**
     * The caller MUST set the appropriate parameters.
     */
    public TransferId(TransferType type) {
        this.type = type;
    }
    /**
     * Instantiating all necessary values.
     * @param type transfer type.
     * @param source the source id.
     * @param destination the destination id.
     * @param filename the filename.
     * @param sourceType the source type/tier (service or client).
     */
    public TransferId(TransferType type, RmiId source, RmiId destination, String filename, TransferSource sourceType) {
        this.type = type;
        this.sourceId = source;
        this.destinationId = destination;
        this.filename = filename;
        this.sourceType = sourceType;
    }
    /**
     * Get the type of transfer activity (upload or download).
     * @return the transfer type.
     */
    public TransferType getType() {
        return type;
    }
    /**
     * Set the transfer activity type.
     * @param type the value.
     */
    public void setType(TransferType type) {
        this.type = type;
    }
    /**
     * Get the source id.
     * @return the source id.
     */
    public RmiId getSourceId() {
        return sourceId;
    }
    /**
     * Set the source id.
     * @param sourceId the id.
     */
    public void setSourceId(RmiId sourceId) {
        this.sourceId = sourceId;
    }
    /**
     * Get the destination id.
     * @return the id.
     */
    public RmiId getDestinationId() {
        return destinationId;
    }
    /**
     * Set the destination id.
     * @param destinationId the id.
     */
    public void setDestinationId(RmiId destinationId) {
        this.destinationId = destinationId;
    }
    /**
     * Get the filename.
     * @return the filename.
     */
    public String getFilename() {
        return filename;
    }
    /**
     * Set the filename.
     * @param filename the value.
     */
    public void setFilename(String filename) {
        this.filename = filename;
    }
    /**
     * Get the source type (client or service).
     * @return the source type.
     */
    public TransferSource getSourceType() {
        return sourceType;
    }
    /**
     * Set the source type.
     * @param sourceType the value.
     */
    public void setSourceType(TransferSource sourceType) {
        this.sourceType = sourceType;
    }
    public String toString() {
        StringBuilder buf = new StringBuilder();
        buf.append(type);
        buf.append(" Filename:" + filename);
        buf.append(" Source:" + sourceId);
        buf.append(" Destination:" + destinationId);
        buf.append(" " + sourceType);
        return buf.toString();
    }
    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((destinationId == null) ? 0 : destinationId.hashCode());
        result = prime * result + ((filename == null) ? 0 : filename.hashCode());
        result = prime * result + ((sourceId == null) ? 0 : sourceId.hashCode());
        result = prime * result + ((sourceType == null) ? 0 : sourceType.hashCode());
        result = prime * result + ((type == null) ? 0 : type.hashCode());
        return result;
    }
    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        TransferId other = (TransferId) obj;
        if (destinationId == null) {
            if (other.destinationId != null)
                return false;
        } else if (!destinationId.equals(other.destinationId))
            return false;
        if (filename == null) {
            if (other.filename != null)
                return false;
        } else if (!filename.equals(other.filename))
            return false;
        if (sourceId == null) {
            if (other.sourceId != null)
                return false;
        } else if (!sourceId.equals(other.sourceId))
            return false;
        if (sourceType != other.sourceType)
            return false;
        if (type != other.type)
            return false;
        return true;
    }
}
